package cn.hrlly.tao2shou.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.domain.Require;
import cn.hrlly.tao2shou.other.Config;
import cn.hrlly.tao2shou.presenter.RequireDetailsPresenter;
import cn.hrlly.tao2shou.presenter.RequireDetailsPresenterImpl;
import cn.hrlly.tao2shou.utils.ImageUtil;
import cn.hrlly.tao2shou.view.base.BaseActivity;
import cn.hrlly.tao2shou.view.view_interface.RequireDetailsView;

public class RequireDetailsActivity extends BaseActivity implements RequireDetailsView {

    @Bind(R.id.ivPortrait)
    ImageView ivPortrait;
    @Bind(R.id.tvNickname)
    TextView tvNickname;
    @Bind(R.id.tvRequireTime)
    TextView tvRequireTime;
    @Bind(R.id.tvRequireTitle)
    TextView tvRequireTitle;
    @Bind(R.id.tvAccpPrice)
    TextView tvAccpPrice;
    @Bind(R.id.tvRequireDescription)
    TextView tvRequireDescription;
    @Bind(R.id.btnPublisher)
    Button btnPublisher;
    private RequireDetailsPresenter requireDetailsPresenter;
    private Intent intent;
    private ImageLoader imageLoader;
    private Require require;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_require_details);
        //绑定控件
        ButterKnife.bind(this);
        //初始化
        intent=getIntent();
        imageLoader=ImageLoader.getInstance();
        requireDetailsPresenter=new RequireDetailsPresenterImpl(this);
        requireDetailsPresenter.showRequireDetails();
    }

    //btnSeller点击事件，跳转至聊天界面,sellerID可以通过showRequireDetails方法传回的数据获取
    @OnClick(R.id.btnPublisher)
    public void publisher(){
        //这里由任天鑫写
        require.getPublisherId();//publishID这样获取
    }

    //以下是对activity的操作
    @Override
    public String getRequireId() {
        return intent.getStringExtra(Config.key_require_id);
    }

    @Override
    public void showRequireDetails(Require require) {
        this.require=require;
        System.out.println(require.getRequireDescription());
        tvRequireTitle.setText(require.getRequireTitle());
        tvRequireTime.setText(require.getRequireTime());
        tvRequireDescription.setText(require.getRequireDescription());
        tvAccpPrice.setText(require.getAcceptablePrice()+"元");
        tvNickname.setText(require.getPublisherNickname());
        imageLoader.displayImage(require.getPublisherPortrait(),ivPortrait, ImageUtil.getOptions());
    }

    @Override
    public void showMessage(int errorMessage) {
        Toast.makeText(this,errorMessage,Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showMessage(String errorMessage) {
        Toast.makeText(this,errorMessage,Toast.LENGTH_SHORT).show();
    }
}
